		<script>
		

			$(document).ready(function(){
				
				//设置cookie
				function setCookie(c_name,value,expiredays)
				{
					var exdate=new Date()
					exdate.setDate(exdate.getDate()+expiredays)
					document.cookie=c_name+ "=" +escape(value)+
					((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
				}
				
				//销毁cookie
				function destroyCookie(c_name){
					document.cookie.c_name=null;
				}
				
				//获取cookie
				function getCookie(c_name)
				{
				if (document.cookie.length>0)
				  {
				  c_start=document.cookie.indexOf(c_name + "=")
				  if (c_start!=-1)
					{ 
					c_start=c_start + c_name.length+1 
					c_end=document.cookie.indexOf(";",c_start)
					if (c_end==-1) c_end=document.cookie.length
						return unescape(document.cookie.substring(c_start,c_end))
					} 
				  }
				return ""
				}

				var headimgurl="<?php echo $userinfo->headimgurl;?>";
				var nickname="<?php echo $userinfo->nickname;?>";
				//var imgUrl = "http://7xllr2.com1.z0.glb.clouddn.com/guitar-logo.jpg",
				var imgUrl = headimgurl,
                shareTitle = nickname+' 弹吉他',
				lineLink="https://www.1302am.com/guitar/index.php?m=home&a=share&serverId="+getCookie("serverId")+"&headimgurl="+headimgurl+"&nickname="+nickname,
                descContent = "刚刚弹奏一吉他，你能听出是哪歌么？";
				
				 /*页面缩放*/
                window.winWidth = $(window).width()/320;
                $('.wapper').css("zoom", winWidth).fadeIn(300);	

					wx.config({
						debug: false,
						appId: '{$signPackage["appId"]}',
						timestamp: '{$signPackage["timestamp"]}',
						nonceStr: '{$signPackage["nonceStr"]}',
						signature: '{$signPackage["signature"]}',
						jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo',
								'startRecord',
								'stopRecord',
								'onVoiceRecordEnd',
								'playVoice',
								'pauseVoice',
								'stopVoice',
								'onVoicePlayEnd',
								'uploadVoice',
								'downloadVoice'
						]  // 功能列表，我们要使用JS-SDK的什么功能
					});
					
					wx.checkJsApi({
						jsApiList: [
							'startRecord',
							'stopRecord',
							'onVoiceRecordEnd',
							'playVoice',
							'pauseVoice',
							'stopVoice',
							'onVoicePlayEnd',
						], // 需要检测的JS接口列表，所有JS接口列表见附录2,
						success: function(res) {
							 //alert(res);
							// 以键值对的形式返回，可用的api值true，不可用为false
							// 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
						}
					});

					wx.ready(function(){
						
						//获取“分享到朋友圈”按钮点击状态及自定义分享内容接口
						wx.onMenuShareTimeline({
							title: shareTitle, // 分享标题
							link:lineLink,
							imgUrl: imgUrl, // 分享图标
							success: function () {
								// 用户确认分享后执行的回调函数
							},
							cancel: function () {
								// 用户取消分享后执行的回调函数
							}
						});
						
						// 获取“分享给朋友”按钮点击状态及自定义分享内容接口
						wx.onMenuShareAppMessage({
							title: shareTitle, // 分享标题
							desc: descContent, // 分享描述
							link:lineLink,
							imgUrl: imgUrl, // 分享图标
							type: 'link', // 分享类型,music、video或link，不填默认为link
							success: function () {
								// 用户确认分享后执行的回调函数
							},
							cancel: function () {
								// 用户取消分享后执行的回调函数
							}
						});
						
						// 获取“分享到QQ”按钮点击状态及自定义分享内容接口
						wx.onMenuShareQQ({
							title: shareTitle, // 分享标题
							desc: descContent, // 分享描述
							link: lineLink, // 分享链接
							imgUrl: imgUrl, // 分享图标
							success: function () {
								// 用户确认分享后执行的回调函数
							},
							cancel: function () {
								// 用户取消分享后执行的回调函数
							}
						});
						// 获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口
						wx.onMenuShareWeibo({
							title: shareTitle, // 分享标题
							desc: descContent, // 分享描述
							link: lineLink, // 分享链接
							imgUrl: imgUrl, // 分享图标
							success: function () {
								// 用户确认分享后执行的回调函数
							},
							cancel: function () {
								// 用户取消分享后执行的回调函数
							}
						});

						//开始录音
						$(".onn").click(function(){
							// alert("hello");
							//$(this).css("background","#046b0b");
							clearInterval(window.backRoate);
							$(".pan").css("-webkit-transform","rotate(0deg)");
							$(".pan").css("-ms-transform","rotate(0deg)");
							$(".pan").css("-moz-transform","rotate(0deg)");
							$(".pan").css("-o-transform","rotate(0deg)");
							$(".pan").css("transform","rotate(0deg)");
							wx.startRecord();
							$(".onn").css({"display":"none"});
							$(".off").css({"display":"block"});
						});
						
						//var localId="";	//音频地址
							
						//自动停止录音
						wx.onVoiceRecordEnd({
							// 录音时间超过一分钟没有停止的时候会执行 complete 回调
							complete: function (res) {
								localId = res.localId; 
								//上传录音，设置cookie
								wx.uploadVoice({
									localId: localId, // 需要上传的音频的本地ID，由stopRecord接口获得
									isShowProgressTips: 1, // 默认为1，显示进度提示
										success: function (res) {
										var serverId = res.serverId; // 返回音频的服务器端ID
										setCookie("serverId",serverId);
										$(".onn").css({"display":"block"});
										$(".off").css({"display":"none"});
										
										wx.downloadVoice({
											serverId: serverId, // 需要下载的音频的服务器端ID，由uploadVoice接口获得
											isShowProgressTips: 1, // 默认为1，显示进度提示
											success: function (res) {
												var localId = res.localId; // 返回音频的本地ID
												wx.playVoice({
													localId: localId, // 需要播放的音频的本地ID，由stopRecord接口获得
												});
												
												//转盘旋转效果
												$(".play").attr("src","__PUBLIC__/images/stop.png");
													var deg=0;
													window.backRoate = setInterval(function(){
														deg++;
														if(deg==360){
															deg=0;
														}
														$(".play").attr("src","__PUBLIC__/images/stop.png");
														$(".pan").css("-webkit-transform","rotate("+deg+"deg)");
														$(".pan").css("-ms-transform","rotate("+deg+"deg)");
														$(".pan").css("-moz-transform","rotate("+deg+"deg)");
														$(".pan").css("-o-transform","rotate("+deg+"deg)");
														$(".pan").css("transform","rotate("+deg+"deg)");
													},20);
											}
										});
										
									
									}
								});
							
								
								
							}
						});
						
						//监听语音播放完毕接口
						wx.onVoicePlayEnd({
							success: function (res) {
								localId = res.localId; // 返回音频的本地ID
								// alert(localId);
								clearInterval(window.backRoate);
								$(".pan").css("-webkit-transform","rotate(0deg)");
								$(".pan").css("-ms-transform","rotate(0deg)");
								$(".pan").css("-moz-transform","rotate(0deg)");
								$(".pan").css("-o-transform","rotate(0deg)");
								$(".pan").css("transform","rotate(0deg)");
								$(".play").attr("src","__PUBLIC__/images/play.png");
							}
						});
					
						//停止录音
						// var lineLink;
						$(".off").click(function(){
							wx.stopRecord({
									success: function (res) {
										localId = res.localId;
										//上传录音
										wx.uploadVoice({
											localId: localId, // 需要上传的音频的本地ID，由stopRecord接口获得
											isShowProgressTips: 1, // 默认为1，显示进度提示
											success: function (res) {
												var serverId = res.serverId; // 返回音频的服务器端ID
												setCookie("serverId",serverId);

												//改变按钮效果
												$(".off").css({"display":"none"});
												$(".onn").css({"display":"block"});
												
												$(".play").attr("src","__PUBLIC__/images/stop.png");
													var deg=0;
													window.backRoate = setInterval(function(){
														deg++;
														if(deg==360){
															deg=0;
														}
														$(".play").attr("src","__PUBLIC__/images/stop.png");
														$(".pan").css("-webkit-transform","rotate("+deg+"deg)");
														$(".pan").css("-ms-transform","rotate("+deg+"deg)");
														$(".pan").css("-moz-transform","rotate("+deg+"deg)");
														$(".pan").css("-o-transform","rotate("+deg+"deg)");
														$(".pan").css("transform","rotate("+deg+"deg)");
													},20);
														
												//播放
												wx.playVoice({
														localId: localId // 需要播放的音频的本地ID，由stopRecord接口获得
												});
												
												//监听播放完毕
												wx.onVoicePlayEnd({
													success: function (res) {
														var localId = res.localId; // 返回音频的本地ID
															clearInterval(window.backRoate);
															$(".play").attr("src","__PUBLIC__/images/play.png");
															$(".pan").css("-ms-transform","rotate(0deg)");
															$(".pan").css("-moz-transform","rotate(0deg)");
															$(".pan").css("-o-transform","rotate(0deg)");
															$(".pan").css("transform","rotate(0deg)");
														
													}
												});
												
												
											 },fail:function(){
												
												alert("上传失败");
												
											}
										});
										
									},
							});
		
						});
						
		

						/*播放和停止播放*/
						// var tag=0;
						$(".play").click(function(){
							var deg=0;
							if($(this).attr("src")=="__PUBLIC__/images/play.png"){
								 // alert(serverId);
								 serverId =getCookie("serverId");
								 // alert(serveId);
								wx.downloadVoice({
									serverId: serverId, // 需要下载的音频的服务器端ID，由uploadVoice接口获得
									isShowProgressTips: 1, // 默认为1，显示进度提示
									success: function (res) {
										var localId = res.localId; // 返回音频的本地ID
										// alert(localId);
										//播放
										wx.playVoice({
												localId: localId// 需要播放的音频的本地ID，由stopRecord接口获得
										});
										
										clearInterval(window.backRoate);
										$(".play").attr("src","__PUBLIC__/images/stop.png");
										window.backRoate = setInterval(function(){
											deg++;
											if(deg==360){
												deg=0;
											}
											$(".pan").css("-webkit-transform","rotate("+deg+"deg)");
											$(".pan").css("-ms-transform","rotate("+deg+"deg)");
											$(".pan").css("-moz-transform","rotate("+deg+"deg)");
											$(".pan").css("-o-transform","rotate("+deg+"deg)");
											$(".pan").css("transform","rotate("+deg+"deg)");
										},20);
										return;
									},
									fail:function(){
										alert("下载音频失败了");
									}
								});
								
								
							}else{
								// alert("hello");
								// alert(localId);
								wx.stopVoice({
									localId: localId, // 需要停止的音频的本地ID，由stopRecord接口获得
								});
								clearInterval(window.backRoate);
								$(this).attr("src","__PUBLIC__/images/play.png");
								$(".pan").css("-ms-transform","rotate(0deg)");
								$(".pan").css("-moz-transform","rotate(0deg)");
								$(".pan").css("-o-transform","rotate(0deg)");
								$(".pan").css("transform","rotate(0deg)");
								return;
								
							}
							
							
						});
						
						wx.error(function(res){
						// config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，也可以在返回的res参数中查看，对于SPA可以在这里更新签名。
							console.log(res);
							//alert(res);
						});
						
						
						
					});
	
		});	
		</script>
		
	</head>
	<body>
		<div class="wapper">
			<div class="avatar">
				<img src="{$userinfo->headimgurl}"  class="avatar_img"/>
				<span class="uname">{$userinfo->nickname}</span>
			</div>
			<div class="main">
				
				<div class="CD">
					<img class="pan" src="__PUBLIC__/images/guitar.jpg"/>
						<img class="play" src="__PUBLIC__/images/play.png"/>
				</div>
				
				<div class="an">
					<a class="onn weui_btn weui_btn_primary" style="text-decoration:none;">开始录音</a>
					<a class="off weui_btn weui_btn_warn" style="margin-top:0px;">停止录音</a>
				</div>
			</div>
		</div>
	</body>
	



